package tpo.wmb.consumer.service.impl;

import com.github.pagehelper.PageInfo;
import dto.Dto;
import dto.ShowWares;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import pojo.BuyOrder;
import pojo.BuyReturn;
import pojo.DetailList;
import pojo.User;
import tpo.wmb.consumer.client.Order_FeignClient;
import tpo.wmb.consumer.service.OrderService;
import until.OrderCoderUtil;

import javax.annotation.Resource;
import java.beans.Transient;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class OrderServiceImpl implements OrderService {

    @Resource
    private Order_FeignClient client;


    @Override
    public Dto<PageInfo<BuyOrder>> selectOrderList0(Map<String, Object> map) {
        return client.selectOrderList(map);
    }

    @Override
    public Dto<BuyOrder> selectOrder0(Integer id) {
        return client.selectOrder(id);
    }

    @Override
    public Integer updateOrder0(BuyOrder buyOrder) {
        return client.updateOrder(buyOrder);
    }

    @Override
    public String insertOrder0( BuyOrder buyOrder) {
        buyOrder.setCode(OrderCoderUtil.getDinghuoCode(null));
        buyOrder.setCreateDate(new Date());
        int a = client.insertOrder(buyOrder);
        if(a>0){
            return buyOrder.getCode();
        }else {
            return null;
        }

    }

    @Override
    public Integer deleteOrder0(Integer id) {
        return client.deleteOrder(id);
    }

    // ++++++++++++++++++++++++++++++++++++++++++++++++++++++分割线---------------------------------------


    @Override
    public PageInfo<BuyReturn> selectBuyReturnList(Map<String, Object> map) {
        Dto<PageInfo<BuyReturn>> dto = client.selectBuyReturnList(map);
        return dto.getObj();
    }

    @Override
    public BuyReturn selectBuyReturn(Integer id) {
        Dto<BuyReturn> dto = client.selectBuyReturn(id);
        return dto.getObj();
    }

    @Override
    public Integer updateBuyReturn(BuyReturn buyReturn) {
        return client.updateBuyReturn(buyReturn);
    }

    @Transactional
    @Override
    public String insertBuyReturn(BuyReturn buyReturn) {
        buyReturn.setCode(OrderCoderUtil.getTuihuoCode(null));
        buyReturn.setCreateDate(new Date());
        int a = client.insertBuyReturn(buyReturn);
        if(a>0){
            return buyReturn.getCode();
        }else {
            return null;
        }
    }

    @Override
    public Integer deleteBuyReturn(Integer id) {
        return client.deleteBuyReturn(id);
    }



    // ++++++++++++++++++++++++++++++++++++++++++++++++++++++分割线---------------------------------------

    @Override
    public List<ShowWares> selectDetailList(String orderId, Integer type) {
        return client.selectDetailList(orderId,type);
    }

    @Override
    public List<ShowWares> selectDetailList2(String orderId, Integer type) {
        return client.selectDetailList2(orderId, type);
    }

    @Override
    public Integer insertDetailList(DetailList detailList) {
        return client.insertDetailList(detailList);
    }

    @Override
    public Integer updateDetailList(DetailList detailList) {
        return client.updateDetailList(detailList);
    }

    @Override
    public Integer deleteDetailList(Integer id) {
        return client.deleteDetailList(id);
    }

    @Override
    public Map<String, Object> seeUpdateBuyReturn(Integer id) {
        return client.seeUpdateBuyReturn(id);
    }

    @Override
    public Map<String, Object> detailListWares(String orderId) {
        return null;
    }

    @Override
    public User orderUser(Integer orderId) {
        return client.orderUser(orderId);
    }

    @Override
    public Integer updateOrderState(Integer orderStaId, Integer recStaId,Integer id) {
        return client.updateOrderState(orderStaId,recStaId,id);
    }

    @Override
    public List<BuyOrder> selectOrderList2(Integer userId) {
        return client.selectOrderList2(userId);
    }

    @Override
    public Integer updateOrder2(BuyOrder buyOrder) {
        return client.updateOrder2(buyOrder);
    }

    @Override
    public Integer updateOrder3(String  code, BigDecimal integer) {
        return client.updateOrder3(code, integer);
    }

    @Override
    public Integer updateBuyReturnState(Integer orderSta, Integer receSta, Integer id) {
        return client.updateBuyReturnState(orderSta, receSta, id);
    }

    @Override
    public BuyReturn selectBuyReturn2(String code) {
        return client.selectBuyReturn2(code);
    }

    @Override
    public Integer updateBuyReturn2(String code, BigDecimal bigDecimal) {
        return client.updateBuyReturn2(code, bigDecimal);
    }

    @Override
    public BuyOrder selectOrdeCoder(String code) {
        return client.selectOrdeCoder(code);
    }

    @Override
    public Integer updateDetailList2(List<DetailList> list) {
        return client.updateDetailList2(list);
    }


}
